package com.Ivy.exercise.Lei;

import java.io.*;

/**
 * 实例化和反实例化
 */
public class stuTest {
    public static void main(String[] args) {
        fanSLH();
    }
    public static void ShiLiHua (){
            //创建一个Student类的实例对象
            Student stu=new Student("萨沙",157,true);
            try (     //创建一个输出流对象，将内存中的stu对象的信息，写入我们的外部文件中去
                      ObjectOutputStream oos=new ObjectOutputStream(
                              new FileOutputStream("C:\\Users\\vina\\Desktop\\testDriver1\\student.txt"));) {
                //将对象写出
                oos.writeObject(stu);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    public static void fanSLH() {
        try( ObjectInputStream ois=new ObjectInputStream(
                new FileInputStream("C:\\Users\\vina\\Desktop\\testDriver1\\student.txt"));) {
            //获取外部文件存储的对象信息
            try {
                Object ob=ois.readObject();
                System.out.println(ob);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}



